package animation.sort.algorithms;

import animation.sort.SortAnimation;
import animation.core.AlgorithmMonitorModel;

public class SelectionSort
        extends SortAnimation
{
    public String toString()
    {
        return "Selection Sort";
    }

    protected void sort(int array[])
            throws Exception
    {
        for (int i = 0; i < array.length; i++) {
            int min = i;
            monitorModel.setVariableValue("i", i);
            monitorModel.setVariableValue("min", min);
            markBox(i + 1, array.length - 1);
            for (int j = i + 1; j < array.length; j++) {
                monitorModel.setVariableValue("j", j);
                if (greater(array, min, j)) {
                    min = j;
                    monitorModel.setVariableValue("min", min);
                }
            }
            swap(array, min, i);
        }
    }

    protected void registerSpecificVariables(AlgorithmMonitorModel monitorModel) {
        monitorModel.registerVariable("i", String.valueOf(0));
        monitorModel.registerVariable("j", String.valueOf(0));
        monitorModel.registerVariable("min", String.valueOf(0));
    }
}
